<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
<!--          <a-col :span="24">-->
<!--            <a-form-item label="主键" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <a-input v-decorator="['guid', validatorRules.guid]" placeholder="请输入主键"  ></a-input>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectName']" placeholder="请输入项目名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目类型（1材料设备）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectType']" placeholder="请输入项目类型（1材料设备）"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tenderProjectCode']" placeholder="请输入招标项目编号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tenderProjectName']" placeholder="请输入招标项目名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="是否扶贫项目（1是0否）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['povertyReliefProject']" placeholder="请输入是否扶贫项目（1是0否）"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="公共资源交易类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['publicResourceType']" placeholder="请输入公共资源交易类型"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工程专业类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['engineeringMajorType']" placeholder="请输入工程专业类型"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="入场登记部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['admissionDepartment']" placeholder="请输入入场登记部门"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目行政主管地区" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectAdministrationArea']" placeholder="请输入项目行政主管地区"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="行业主管部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['industryAuthorities']" placeholder="请输入行业主管部门"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="行管部门审批备案编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['managementDeptno']" placeholder="请输入行管部门审批备案编号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['biddingMethod']" placeholder="请输入招标方式"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="资审方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['prequalificationMethod']" placeholder="请输入资审方式"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="递交投标文件方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tenderDocumentsMethod']" placeholder="请输入递交投标文件方式"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标组织形式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tenderOrganizeForm']" placeholder="请输入招标组织形式"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="主体建设单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['mainConstructionUnit']" placeholder="请输入主体建设单位"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="组织机构代码/统一社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['organNo']" placeholder="请输入组织机构代码/统一社会信用代码"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="单位负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['unitResponsiblePerson']" placeholder="请输入单位负责人"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="办公电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['phone']" placeholder="请输入办公电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="移动电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['mobile']" placeholder="请输入移动电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标代理机构名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tenderAgencyName']" placeholder="请输入招标代理机构名称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标代理组织机构代码/统一社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tenderAgencyCode']" placeholder="请输入招标代理组织机构代码/统一社会信用代码"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标负责人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tendererName']" placeholder="请输入招标负责人"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="招标负责人办公电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tendererPhone']" placeholder="请输入招标负责人办公电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="移动电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['tendererMobile']" placeholder="请输入移动电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="项目来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectSource']" placeholder="请输入项目来源"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="入库时间（时间戳）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['version']" placeholder="请输入入库时间（时间戳）" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="交易平台编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['jyptBh']" placeholder="请输入交易平台编号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="行政区划代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['areaCode']" placeholder="请输入行政区划代码"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'FinanBiddingprojectInfoForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          guid: {
            rules: [
              { required: true, message: '请输入主键!'},
            ]
          },
        },
        url: {
          add: "/finanBiddingprojectInfo/add",
          edit: "/finanBiddingprojectInfo/edit",
          queryById: "/finanBiddingprojectInfo/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'guid','projectName','projectType','tenderProjectCode','tenderProjectName','povertyReliefProject','publicResourceType','engineeringMajorType','admissionDepartment','projectAdministrationArea','industryAuthorities','managementDeptno','biddingMethod','prequalificationMethod','tenderDocumentsMethod','tenderOrganizeForm','mainConstructionUnit','organNo','unitResponsiblePerson','phone','mobile','tenderAgencyName','tenderAgencyCode','tendererName','tendererPhone','tendererMobile','projectSource','version','jyptBh','areaCode'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'guid','projectName','projectType','tenderProjectCode','tenderProjectName','povertyReliefProject','publicResourceType','engineeringMajorType','admissionDepartment','projectAdministrationArea','industryAuthorities','managementDeptno','biddingMethod','prequalificationMethod','tenderDocumentsMethod','tenderOrganizeForm','mainConstructionUnit','organNo','unitResponsiblePerson','phone','mobile','tenderAgencyName','tenderAgencyCode','tendererName','tendererPhone','tendererMobile','projectSource','version','jyptBh','areaCode'))
      },
    }
  }
</script>